package com.wzdigit.wms.raw.service.mid;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.mes.basic.api.BasicDataItemDetailApi;
import com.wzdigit.mes.basic.api.BasicSimpleCodeRuleApi;
import com.wzdigit.mes.basic.api.BasicVendorApi;
import com.wzdigit.mes.basic.dto.VendorDTO;
import com.wzdigit.wms.basic.domain.asn.AsnDtl;
import com.wzdigit.wms.basic.domain.asn.AsnDtlGoods;
import com.wzdigit.wms.basic.domain.asn.AsnHeader;
import com.wzdigit.wms.basic.domain.dtos.inventory.UpdateInventoryInputDto;
import com.wzdigit.wms.basic.domain.inventory.Goods;
import com.wzdigit.wms.basic.domain.inventory.GoodsLog;
import com.wzdigit.wms.basic.domain.inventory.InvTrans;
import com.wzdigit.wms.basic.domain.inventory.Lotno;
import com.wzdigit.wms.basic.domain.mid.JobSyncErrorData;
import com.wzdigit.wms.basic.domain.order.TrsnDtl;
import com.wzdigit.wms.basic.domain.order.TrsnDtlGoods;
import com.wzdigit.wms.basic.domain.order.TrsnHeader;
import com.wzdigit.wms.basic.domain.transfer.GdnDtl;
import com.wzdigit.wms.basic.domain.transfer.GdnHeader;
import com.wzdigit.wms.basic.enums.*;
import com.wzdigit.wms.basic.mapper.core.basic.SkuMapper;
import com.wzdigit.wms.basic.mapper.core.basic.WarehouseMapper;
import com.wzdigit.wms.basic.mapper.core.mid.JobSyncErrorDataMapper;
import com.wzdigit.wms.basic.mapper.core.order.*;
import com.wzdigit.wms.basic.mapper.core.transfer.GdnDtlMapper;
import com.wzdigit.wms.basic.mapper.core.transfer.GdnHeaderMapper;
import com.wzdigit.wms.basic.service.code.CodeMappingService;
import com.wzdigit.wms.basic.service.code.InventoryService;
import com.wzdigit.wms.basic.service.code.LotnoService;
import com.wzdigit.wms.basic.util.common.SeparatorString;
import com.wzdigit.wms.raw.constant.SyncTypeConstant;
import com.wzdigit.wms.raw.domain.dto.HouseQaStatus;
import com.wzdigit.wms.raw.domain.mid.IfReviewresult;
import com.wzdigit.wms.raw.exception.SyncException;
import com.wzdigit.wms.raw.mapper.mid.IfAsnDtlMapper;
import com.wzdigit.wms.raw.mapper.mid.IfAsnHeaderMapper;
import com.wzdigit.wms.raw.mapper.mid.IfReviewresultMapper;
import com.wzdigit.wms.raw.service.wmscommon.core.GoodsService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 接口中间表-送货单 同步 收货单
 * </p>
 *
 * @author chao shuai
 * @since 2021-03-16
 */
@Service
public class IfReviewResultService {

    @Autowired
    private AsnHeaderMapper asnHeaderMapper;

    @Autowired
    private AsnDtlMapper asnDtlMapper;

    @Autowired
    private JobSyncErrorDataMapper jobSyncErrorDataMapper;

    @Reference(version = "${dubbo.consumers.basic.vendor.api:1.0.0}", check = false, timeout = 300000)
    private BasicVendorApi  basicVendorApi;
    @Reference(version = "${dubbo.consumers.basic.data.item.detail.api:1.0.0}", check = false, timeout = 300000)
    private BasicDataItemDetailApi dataItemDetailApi;

    @Autowired
    private SyncErrorDataService syncErrorDataService;

    @Autowired
    CodeMappingService codeMappingService;
    
    @Autowired
    MappingHouseService mappingHouseService;

    @Autowired
    WarehouseMapper warehouseMapper;

    @Autowired
    AsnDtlGoodsMapper asnDtlGoodsMapper;

    @Autowired
    IfReviewresultMapper ifReviewresultMapper;

    @Autowired
    GoodsService goodsService;

    @Autowired
    TrsnDtlGoodsMapper trsnDtlGoodsMapper;
    @Autowired
    TrsnDtlMapper trsnDtlMapper;
    @Autowired
    TrsnHeaderMapper trsnHeaderMapper;
    @Autowired
    LotnoService lotnoService;
    @Autowired
    GdnHeaderMapper gdnHeaderMapper;
    @Autowired
    GdnDtlMapper gdnDtlMapper;


    @Autowired
    InventoryService inventoryService;
    @Reference(version = "${dubbo.consumers.basic.simple.code.rule.api:1.0.0}", check = false)
    private BasicSimpleCodeRuleApi basicSimpleCodeRuleApi;

    @Value(value = "${default_owner.code}")
    private String DEFAULT_OWNER;

    private final String syncType = SyncTypeConstant.IF_REVIEW_RESULT_TO_GDN;

    public List<IfReviewresult> selectSyncData() {

        QueryWrapper<IfReviewresult> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("Attribute10","1").or().isNull("Attribute10");
        List<IfReviewresult> selectSyncData = ifReviewresultMapper.selectList(queryWrapper);

        return selectSyncData;
    }


    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public void syncData(IfReviewresult data) throws Exception {
        String mblnr = data.getMblnr(); //物料凭证 作为单号
        //查询仓库
       /* HouseQaStatus houseQaStatus = mappingHouseService.getWmsHourseIdBySapHourseCode(data.getLgortBhg());
        if(houseQaStatus==null){
            throw new SyncException(syncType, mblnr, "SAP仓库编码" + data.getLgortBhg() + "无法转换成WMS仓库");
        }*/

        //查询对应的订单明细
        List<AsnDtl> asnDtlList = asnDtlMapper.selectList(new QueryWrapper<AsnDtl>(new AsnDtl().setUdf4(data.getPrueflos())));//判检返回的批次号存在自定义字段5
        if(asnDtlList==null||asnDtlList.size()==0){//
            throw new SyncException(syncType, data.getPrueflos(), "未找到对应的入库单明细");
        }
        //获取主表信息
        QueryWrapper queryWrapper = new QueryWrapper<AsnHeader>();
        queryWrapper.setEntity(new AsnHeader().setAsnHeaderId(asnDtlList.get(0).getAsnHeaderId()));
        AsnHeader asnHeader = asnHeaderMapper.selectOne(queryWrapper);
        //获取凭证是否已经生成单据，不能重复生成和改变
        GdnHeader gdnHeaderRecord = gdnHeaderMapper.selectOne(new QueryWrapper<>(new GdnHeader().setGdnNo(mblnr)));
        if(gdnHeaderRecord!=null){
            throw new SyncException(syncType, data.getMblnr(), "对应的单据已经生成，不能重复生成");
        }

        //创建出库单
        GdnHeader gdnHeader = new GdnHeader();
        //同步主表信息
        gdnHeader.setGdnNo(mblnr);
        gdnHeader.setGdnType(GdnTypeEnum.D22.code);
        gdnHeader.setConsigneeId(asnHeader.getVendorId().longValue());
        VendorDTO vendor = basicVendorApi.getVendorById(asnHeader.getVendorId());
        if (vendor != null) {
            gdnHeader.setConsigneeName(vendor.getVendorName());
        }
        //获取供应商名称

        gdnHeader.setGdnCreateUser(data.getCreateUser());
        gdnHeader.setGdnCreateTime(data.getCreateTime());
        gdnHeader.setFactory(asnHeader.getFactory());
        gdnHeader.setOwner(asnHeader.getOwner());
        gdnHeader.setShipDate(new Date());
        gdnHeader.setSourceShipNotice(asnHeader.getAsnNo());//存储来源单号
        //判断新建还是更新
        gdnHeader.setStatus(GdnHeaderStatusEnum.CREATE.getCode());
        gdnHeader.setCreateUser("system");
        gdnHeader.setCreateTime(new Date());
        gdnHeaderMapper.insert(gdnHeader);
        Integer gdnLineNo = 0 ;
        for (AsnDtl asnDtl : asnDtlList){
            GdnDtl gdnDtl = new GdnDtl();
            gdnDtl.setWhsId(asnDtl.getWhsId());//设置库位
            gdnDtl.setGdnHeaderId(gdnHeader.getGdnHeaderId());
            gdnDtl.setSkuId(asnDtl.getSkuId());
            gdnDtl.setGdnLineNo(++gdnLineNo);
            gdnDtl.setOrderQty(asnDtl.getOrderQty());
            gdnDtl.setStatus(GdnDtlStatusEnum.CREATE.code);
            gdnDtl.setUnit(asnDtl.getUnit());
            gdnDtl.setCreateTime(new Date());
            gdnDtl.setQaStatus(QaStatusEnum.NG.code);
            gdnDtl.setCreateUser("system");
            gdnDtl.setSourceShipNoticeItem(asnDtl.getAsnLineNo());
            gdnDtlMapper.insert(gdnDtl);
        }



        int row = ifReviewresultMapper.updateFlagById(data.getIfReviewresultId());
        //检查是否有同步失败的记录，有则更新为成功
        JobSyncErrorData jobSyncErrorData = jobSyncErrorDataMapper.getSyncErrorDataByTypeAndCode(syncType, mblnr);
        if (jobSyncErrorData != null && 0 == jobSyncErrorData.getIsSuccess()) {
            syncErrorDataService.updateSuccessByCode(syncType, mblnr);
        }
       // Shift.fatal("111");
    }

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public void changeGoodsQaStatus(IfReviewresult data) throws Exception {
        String userName= "system";
        //通过批次号查询对应的入库单明细集合

        List<AsnDtl> asnDtlList = asnDtlMapper.selectList(new QueryWrapper<AsnDtl>(new AsnDtl().setUdf4(data.getPrueflos())));//判检返回的批次号存在自定义字段4
        if(asnDtlList==null||asnDtlList.size()==0){
            throw new SyncException(syncType, data.getPrueflos(), "未找到对应的入库单明细");
        }
        QueryWrapper queryWrapper = new QueryWrapper<AsnHeader>();
        queryWrapper.setEntity(new AsnHeader().setAsnHeaderId(asnDtlList.get(0).getAsnHeaderId()));
        AsnHeader asnHeader = asnHeaderMapper.selectOne(queryWrapper);

        // 品质状态【旧、新】
        Integer oldQaStatus = asnDtlList.get(0).getQaStatus();
        Integer newQaStatus = QaStatusEnum.OK.code;
        //判断品质状态是否为不合格
        if(oldQaStatus!=QaStatusEnum.NG.getCode()){
            throw new SyncException(syncType, data.getPrueflos(), "对应入库单明细SN状态已经被更改");
        }
        // 系统时间
        Date date = new Date();
        // 处理过的goodsSn
        Set<String> goodsSnSet = new HashSet<>();
        //获取入库单明细对应的产品
        for (AsnDtl asnDtl : asnDtlList) {
            // 当前送货单明细条码
            QueryWrapper<AsnDtlGoods> asnDtlGoodsQueryWrapper = new QueryWrapper<AsnDtlGoods>();
            asnDtlGoodsQueryWrapper.eq("ASN_DTL_ID", asnDtl.getAsnDtlId());
            List<AsnDtlGoods> asnDtlGoodsList = asnDtlGoodsMapper.selectList(asnDtlGoodsQueryWrapper);

            // 条码SN
            List<String> dtlSnList = asnDtlGoodsList.stream().map(AsnDtlGoods::getGoodsSn).distinct().collect(Collectors.toList());
            List<Goods> dtlGoodsList = goodsService.selectBySnList(dtlSnList);

            // 新增库存凭证--主档和明细
            BigDecimal trsnQty = asnDtlGoodsList.stream().map(t -> t.getQty()).reduce(BigDecimal.ZERO, BigDecimal::add);
            TrsnDtl trsnDtl1 = insertTrsnHeaderAndTrsnDtl(oldQaStatus, trsnQty, asnDtl, asnHeader, -1, "system", date);
            TrsnDtl trsnDtl2 = insertTrsnHeaderAndTrsnDtl(newQaStatus, trsnQty, asnDtl, asnHeader, 1, "system", date);

            // 根据【仓库、库位、货主、物料、组织、供应商、批次号、库存性质】分组统计
            Map<String, List<Goods>> goodsMap = dtlGoodsList.stream().collect(Collectors.groupingBy(t ->
                    (t.getWhsId() + "#" + t.getLocId() + "#" + t.getOwner() + "#" +
                            t.getSkuId() + "#" + t.getFactory() + "#" + t.getVendorId() + "#" +
                            t.getLotno() + "#" + t.getInvAttr() + "#"), Collectors.toList()));
            for (String goodsKey : goodsMap.keySet()) {
                List<Goods> goodsList = goodsMap.get(goodsKey);
                Goods invGoods = goodsList.get(0);
                List<String> snList = goodsList.stream().map(Goods::getGoodsSn).distinct().collect(Collectors.toList());
                BigDecimal qty = asnDtlGoodsList.stream().filter(t -> snList.contains(t.getGoodsSn())).map(t -> t.getQty()).reduce(BigDecimal.ZERO, BigDecimal::add);

                // 扣减库存【原来QA状态库存】
                UpdateInventoryInputDto oldInv = new UpdateInventoryInputDto();
                oldInv.setWhsId(invGoods.getWhsId());			// 仓库
                oldInv.setOwner(invGoods.getOwner());			// 货主
                oldInv.setSkuId(invGoods.getSkuId());			// 物料
                oldInv.setFactory(invGoods.getFactory());		// 组织
                oldInv.setLotNo(invGoods.getLotno());			// 批次号
                oldInv.setVendorId(invGoods.getVendorId());		// 供应商
                oldInv.setInvAttr(invGoods.getInvAttr());		// 库存性质
                oldInv.setQaStatus(oldQaStatus);				// 品质状态【旧】
                oldInv.setUnit(invGoods.getUnit());				// 单位
                oldInv.setLocId(invGoods.getLocId());       	// 库位
                oldInv.setQty(qty.negate());					// 数量【-】
                oldInv.setOperator(userName);

                // 库存日志【原来QA状态库存】
                InvTrans oldInvLog = new InvTrans();
                oldInvLog.setOpCode(OpCodeEnum.INSPECTIONRESULT.getDescription());
                oldInvLog.setDocType(asnHeader.getAsnType());
                oldInvLog.setDocNo(asnDtl.getAsnNo());
                oldInvLog.setDocLineNo(asnDtl.getAsnLineNo());
                oldInvLog.setTrsnNo(trsnDtl1.getNoteNo());
                oldInvLog.setTrsnLineNo(trsnDtl1.getNoteLineNo());
                oldInvLog.setStatus(InvTransStatusEnum.FINISHED.getCode());
                oldInvLog.setTransTime(date);
                oldInvLog.setOperator(userName);
                oldInvLog.setTransQty(oldInv.getQty());
                oldInvLog.setCreateTime(date);
                oldInvLog.setCreateUser(userName);

                // 扣减库存
                inventoryService.inventoryOut(oldInv, oldInvLog);

                //------------------------------------------//

                // 增加库存【判检后新的QA状态库存】
                UpdateInventoryInputDto newInv = new UpdateInventoryInputDto();
                newInv.setWhsId(invGoods.getWhsId());			// 仓库
                newInv.setOwner(invGoods.getOwner());			// 货主
                newInv.setSkuId(invGoods.getSkuId());			// 物料
                newInv.setFactory(invGoods.getFactory());		// 组织
                newInv.setLotNo(invGoods.getLotno());			// 批次号
                newInv.setVendorId(invGoods.getVendorId());		// 供应商
                newInv.setInvAttr(invGoods.getInvAttr());		// 库存性质
                newInv.setQaStatus(newQaStatus);				// 品质状态【新】
                newInv.setUnit(invGoods.getUnit());				// 单位
                newInv.setLocId(invGoods.getLocId());       	// 库位
                newInv.setQty(qty);								// 数量【+】
                newInv.setOperator(userName);

                // 库存日志【判检后新的QA状态库存】
                InvTrans newInvLog = new InvTrans();
                newInvLog.setOpCode(OpCodeEnum.INSPECTIONRESULT.getDescription());
                newInvLog.setDocType(asnHeader.getAsnType());
                newInvLog.setDocNo(asnDtl.getAsnNo());
                newInvLog.setDocLineNo(asnDtl.getAsnLineNo());
                newInvLog.setTrsnNo(trsnDtl2.getNoteNo());
                newInvLog.setTrsnLineNo(trsnDtl2.getNoteLineNo());
                newInvLog.setStatus(InvTransStatusEnum.FINISHED.getCode());
                newInvLog.setTransTime(date);
                newInvLog.setOperator(userName);
                newInvLog.setTransQty(newInv.getQty());
                newInvLog.setCreateTime(date);
                newInvLog.setCreateUser(userName);

                // 增加库存
                inventoryService.inventoryIn(newInv, newInvLog);

                // 遍历条码
                for (Goods goods : goodsList) {
                    // 新增库存凭证--明细货品清单
                    BigDecimal goodsQty = asnDtlGoodsList.stream().filter(t -> goods.getGoodsSn().equals(t.getGoodsSn())).findFirst().map(t -> t.getQty()).get();
                    insertTrsnDtlGoods(trsnDtl1.getTrsnDtlId(), oldQaStatus, goods.getGoodsId(), goods.getGoodsSn(), goodsQty, userName, date);
                    insertTrsnDtlGoods(trsnDtl2.getTrsnDtlId(), newQaStatus, goods.getGoodsId(), goods.getGoodsSn(), goodsQty, userName, date);

                    if(!goodsSnSet.contains(goods.getGoodsSn())) {
                        goodsSnSet.add(goods.getGoodsSn());

                        // 更新货品清单的QA状态
                        String oldGoodsJsonStr = JSON.toJSONString(goods);	//原先的json
                        goods.setQaStatus(newQaStatus);
                        goods.setModifyTime(date);
                        goods.setModifyUser(userName);
                        goodsService.updateById(goods);
                        String newGoodsJsonStr = JSON.toJSONString(goods);	//更新后的json

                        // 新增货品清单的日志
                        GoodsLog goodsLog = new GoodsLog();
                        goodsLog.setGoodsSn(goods.getGoodsSn());
                        goodsLog.setOpCode("判检" + goods.getGoodsSn());
                        goodsLog.setReason("变更品质状态");
                        goodsLog.setOperator("OA评审改判合格");
                        goodsLog.setUpdateContent("未更新的：" + oldGoodsJsonStr + ",更新后的：" + newGoodsJsonStr);
                        goodsLog.setCreateUser(userName);
                        goodsLog.setCreateTime(date);
                        goodsService.insertGoodsLog(goodsLog);
                    }
                }
            }

            // 更新送货单明细
            asnDtl.setQaStatus(newQaStatus);
            asnDtl.setModifyUser(userName);
            asnDtl.setModifyTime(date);
            asnDtlMapper.updateById(asnDtl);

            // 更新送货单明细--货品清单
            AsnDtlGoods asnDtlGoods = new AsnDtlGoods();
            asnDtlGoods.setQaStatus(newQaStatus);
            asnDtlGoods.setModifyUser(userName);
            asnDtlGoods.setModifyTime(date);
            asnDtlGoodsMapper.update(asnDtlGoods, asnDtlGoodsQueryWrapper);

            int row = ifReviewresultMapper.updateFlagById(data.getIfReviewresultId());
            //检查是否有同步失败的记录，有则更新为成功
            JobSyncErrorData jobSyncErrorData = jobSyncErrorDataMapper.getSyncErrorDataByTypeAndCode(syncType, data.getMblnr());
            if (jobSyncErrorData != null && 0 == jobSyncErrorData.getIsSuccess()) {
                syncErrorDataService.updateSuccessByCode(syncType, data.getMblnr());
            }

        }

    }


    private static final String NOTE_NO = "TRSN_ORDER";

    private TrsnDtl insertTrsnHeaderAndTrsnDtl(Integer qaStatus, BigDecimal qty, AsnDtl asnDtl, AsnHeader asnHeader,
                                               int invUpdateFlag, String userName, Date date) throws Exception {
        // 生成凭证号
        String noteNo = basicSimpleCodeRuleApi.GenerateCode(NOTE_NO);
        // 凭证表头
        TrsnHeader trsnHeader = new TrsnHeader();
        trsnHeader.setNoteNo(noteNo);
        trsnHeader.setNoteType(TrsnNoteTypeEnum.DRAW.getCode());	// 翻牌
        trsnHeader.setFmDoc(asnDtl.getAsnNo());
        trsnHeader.setWhsId(asnDtl.getWhsId());
        trsnHeader.setOwner(asnHeader.getOwner());
        trsnHeader.setFactory(asnHeader.getFactory());
        trsnHeader.setVendorId(asnHeader.getVendorId());
        trsnHeader.setFmDoc(SeparatorString.RIGHT_SLASH);
        trsnHeader.setDocRef1(SeparatorString.RIGHT_SLASH);
        trsnHeader.setDocRef2(SeparatorString.RIGHT_SLASH);
        trsnHeader.setDocRef3(SeparatorString.RIGHT_SLASH);
        trsnHeader.setDocRef4(SeparatorString.RIGHT_SLASH);
        trsnHeader.setDocRef5(SeparatorString.RIGHT_SLASH);
        trsnHeader.setComments(SeparatorString.RIGHT_SLASH);
        trsnHeader.setStatus(TrsnHeaderStatusEnum.CMP.code);
        trsnHeader.setCreateUser(userName);
        trsnHeader.setCreateTime(date);
        trsnHeaderMapper.insert(trsnHeader);

        // 凭证明细
        TrsnDtl trsnDtl = new TrsnDtl();
        trsnDtl.setNoteNo(noteNo);
        trsnDtl.setTrsnHeaderId(trsnHeader.getTrsnHeaderId());
        trsnDtl.setFmDoc(asnDtl.getAsnNo());
        trsnDtl.setFmDocLine(asnDtl.getAsnLineNo());
        trsnDtl.setQaStatus(qaStatus);
        trsnDtl.setSkuId(asnDtl.getSkuId());
        trsnDtl.setQty(qty);
        trsnDtl.setUnit(asnDtl.getUnit());
        trsnDtl.setInvUpdateFlag(invUpdateFlag);
        trsnDtl.setNoteLineNo("1");
        trsnDtl.setInvType("X");
        trsnDtl.setStatus(TrsnDtlStatusEnum.CMP.code);
        trsnDtl.setComments(SeparatorString.RIGHT_SLASH);
        trsnDtl.setCreateUser(userName);
        trsnDtl.setCreateTime(date);
        if (asnDtl.getLotno() != null) {
            Lotno lotno = lotnoService.selectByLotno(asnDtl.getLotno());
            if (lotno != null) {
                trsnDtl.setLotAttr1(lotno.getLotAttr1());
                trsnDtl.setLotAttr2(lotno.getLotAttr2());
                trsnDtl.setLotAttr3(lotno.getLotAttr3());
                trsnDtl.setLotAttr4(lotno.getLotAttr4());
                trsnDtl.setLotAttr5(lotno.getLotAttr5());
                trsnDtl.setLotAttr6(lotno.getLotAttr6());
                trsnDtl.setLotAttr7(lotno.getLotAttr7());
                trsnDtl.setLotAttr8(lotno.getLotAttr8());
                trsnDtl.setLotAttr9(lotno.getLotAttr9());
                trsnDtl.setLotAttr10(lotno.getLotAttr10());
                trsnDtl.setLotAttr11(lotno.getLotAttr11());
                trsnDtl.setLotAttr12(lotno.getLotAttr12());
            }
        }
        trsnDtlMapper.insert(trsnDtl);
        return trsnDtl;
    }

    private void insertTrsnDtlGoods(Integer trsnDtlId , Integer qaStatus, Integer goodsId, String goodsSn,
                                    BigDecimal qty, String userName, Date date) throws Exception {
        // 凭证明细-goods
        TrsnDtlGoods trsnDtlGoods = new TrsnDtlGoods();
        trsnDtlGoods.setTrsnDtlId(trsnDtlId);
        trsnDtlGoods.setQaStatus(qaStatus);
        trsnDtlGoods.setGoodsId(goodsId);
        trsnDtlGoods.setGoodsSn(goodsSn);
        trsnDtlGoods.setQty(qty);
        trsnDtlGoods.setStatus(TrsnDtlGoodsStatusEnum.RECEIVED.getCode());
        trsnDtlGoods.setCreateUser(userName);
        trsnDtlGoods.setCreateTime(date);
        trsnDtlGoodsMapper.insert(trsnDtlGoods);
    }


}
